<!--{subtemplate common/header}-->
<script src="{JS_PATH}artDialog/artDialog.js" type="text/javascript"></script>
<script src="{JS_PATH}artDialog/plugins/iframeTools.js" type="text/javascript"></script>
<link rel="stylesheet" href="{JS_PATH}artDialog/skins/default.css">
<!--购物车（有商品）-->
<div class="shopCarbox w1100">
	<div class="shopCar_nav">
		<div class="shopCar_Title-2">填写核对订单</div>
		<div class="shopCar_msg">
			<span class="shopCar_msg_01"><img src="{THEME_PATH}images/homeimages/1_03.png">放入购物车<img src="{THEME_PATH}images/homeimages/9qw_10.png"></span>
			<span class="shopCar_msg_02-2"><img src="{THEME_PATH}images/homeimages/11_03.png">填写核对订单<img src="{THEME_PATH}images/homeimages/9qw_10.png"></span>
			<span class="shopCar_msg_02"><img src="{THEME_PATH}images/homeimages/92_07.png">成功提交订单</span>
		</div>
	</div>
	<div class="w1100" style="margin-top: 7px;">
		<!--确认收货地址-->
		<div class="Shipping-address">
			<span class="entity-fl">确认收货地址</span>
			<span class="entity-fr"><a href="{U('User/Address/address')}" target="_blank">管理收货地址</a></span>
		</div>
		<div class="address-box" id="address-box">
			{loop $user_address $address}
			<div class="add-address-1{if $address['id'] == $address_id} selected{/if}" data-addressid="{$address[id]}" data-province="{$address[province]}" data-city="{$address[city]}" data-district="{$address[district]}" data-address_name="{$address[address_name]}" data-address="{$address[address]}" data-zipcode="{$address[zipcode]}" data-mobile="{$address[mobile]}">
				<div class="border-img-top"><img src="{THEME_PATH}images/homeimages/border-top_03.png" alt="" /></div>
				<div class="border-img-top-2"{if $address['id'] != $address_id} style="display:none;"{/if}><img src="{THEME_PATH}images/homeimages/border-img-1.png" alt="" /></div>
				<p class="add-address-name">
					<span class="add-address-name1">{$address[address_name]}</span>
					<span class="add-address-name2">{$address[mobile]}</span>
					<span class="add-address-name3"{if $address['id'] != $address_id} style="display:none;"{/if}>默认</span>
				<p class="add-address-address"><b>寄送至</b>  {getAreaNameById($address[province])} {getAreaNameById($address[city])} {getAreaNameById($address[district])} {$address[address]}</p>
				<p class="add-address-make"{if $address['id'] != $address_id} style="display:none;"{/if}>修改</p>
			</div>
			{/loop}
			<div class="add-address">添加新地址</div>
		</div>
		<div class="clear"></div>
		<div class="Shipping-address">
			<span class="entity-fl">确认配送&支付方式</span>
			<span class="entity-fr"><!-- <a href="{U('User/Address/address')}" target="_blank">管理收货地址</a> --></span>
		</div>
		<div class="payoff_box">
			<div class="address" id="delivery_box">
				<div class="pay-single">配送方式</div>
				{loop $deliverys $k $delivery}
				<div class="{if $k > 0}pay-margin {/if}pay-choose-1">
					<label for="delivery_id_{$delivery[id]}"><input type="radio" name="delivery_id" value="{$delivery[id]}" id="delivery_id_{$delivery[id]}">&nbsp;{$delivery[name]}<span class="pay-choose-1-msg">{$delivery[descript]}</span></label>
				</div>
				{/loop}
				<div id="delivery_tips" class="error" style="display: none;">请选择收货地址</div>
			</div>
            <div class="line"></div>
			<div class="payoff" id="pay_type_box">
                <div class="pay-single">支付方式</div>
                <div id="pays_tips" class="error">请选择配送方式</div>
			</div>
		</div>
		<div class="Shipping-address">
			<span class="entity-fl">购物清单</span>
			<span class="entity-fr"><a href="{U('Goods/Cart/index')}">返回购物车修改</a></span>
		</div>
	</div>
	<div class="clear"></div>
	<!--商品-->
	<div class="shppingBox">
		<div class="shoppingBox_Title">
			<li class="shopping_01" style="margin-right:560px;">商品</li>
			<li class="shopping_02">单价</li>
			<li class="shopping_03">花费积分</li>
			<li class="shopping_04">数量</li>
			<li class="shopping_05">小计</li>
		</div>
		<!--有特价-->
		{loop $cart_goods_list $r}
		<div class="cart_01">
			<!--商品-->
			<li class="cart_01a">
				<div class="cart_01a_img"><img src="{if $r[goods_img]}{$r[goods_img]}{else}{$r[thumb]}{/if}" width="55" height="55"></div>
				<div class="cart_01a_p"><a class="cart_01a_p1">{msubstr($r[name], 20)}<br><span class="cart_01a_p2">{if $r[spec_text]}[{$r[spec_text]}]{/if}</span></a></div>
				{if ($r['prom_type']=='goods' && $r['prom_id'] > 0 && $r['is_promotion'] == TRUE)}
					<div class="cart_01b_div fr" title="{$r['promotion_name']}">商品促销</div>
				{elseif ($r['prom_type'] == 'timed' && $r['prom_id'] > 0 && $r['is_promotion'] == TRUE)}
					<div class="cart_01b_div fr" title="{$r['promotion_name']}">限时促销</div>
				{/if}
			</li>
			<!--空的-->
			<li class="cart_01c"></li>
			<!--单价-->
			<li class="cart_01c">{MONUNIT}<span class="price">{$r[shop_price]}</span></li>
			<!--积分-->
			<li class="cart_01d"><span class="score">0</span></li>
			<!--数量-->
			<li class="cart_01e" style="color:#646464">{$r[goods_num]}</li>
			<!--小计-->
			<li class="cart_01f">{MONUNIT}<span class="price-total">{$r[total_price]}</span></li>
		</div>
		<div class="clear clearfix"></div>
		{/loop}
		<!--优惠券-->
		<div class="cd_key">
			<span>选择已有优惠劵：</span>
			<select name="sn" class="put" onchange="hd_order.init()">
			{if $coupons_list}
				<option value="">请选择优惠券</option>
				{loop $coupons_list $r}
				<option value="{$r[sn]}">{$r[name]}（{MONUNIT}{$r[value]}）</option>
				{/loop}
			{else}
				<option value="">暂无可用优惠券</option>
			{/if}
			</select>
			<span><a href="{U('User/Coupons/couponslist')}" target="_blank" class="cou12">查看所有优惠券</a></span>
		</div>
		<!--结算-->
	</div>
	<div>
		<div class="agree-order ">
			<div class="agree-order-fl fl">
				<div class="agree-order-fl-1">
					<span class="agree-order-span1">订单备注</span>
					<input type="text" name="postscript" class="agree-order-input">
				</div>
				{if $order_promotions}
				<div class="agree-order-fl-1" id="promotion">
					<span class="agree-order-span1">订单促销</span>
					<select name="promotion_id" id="promotion_id" onchange="hd_order.init()">
						<option value="0">请选择</option>
						{loop $order_promotions $promotion}
						<option value="{$promotion[id]}">{$promotion[name]}</option>
						{/loop}
					</select>
				</div>
				{/if}
				{if getconfig('site_invoice')}
				<div class="agree-order-fl-1">
					<span class="agree-order-span1"><label><input type="checkbox" name="invoicerate" value="1" onclick="switch_tab();hd_order.init();">索取发票</label></span>
				</div>
				<div class="agree-order-fl-2">
					<div class="bill-unit-con" style="display: block;">
						<div class="bill">
							<span>发票抬头：</span>
							<span><input type="text" name="invoice_title" class="bill-input"></span>
							<p style="color: #ff0000;margin-left: 63px;margin-top: 3px;">填写姓名或者公司全名</p>
						</div>
						<div class="bill-people-con">
							<p>发票内容：
								<span>
									<select name="invoice_type" id="in" class="cho-way">
										{loop $invoice_content $t}
										<option value="{$t}">{$t}</option>
										{/loop}
									</select>
								</span>
							</p>
						</div>
					</div>
				</div>
				{/if}
			</div>
			<div class="agree-order-fr fl">
				<p>应付商品金额：{MONUNIT}{$rs[goods_count_price]}</p>
				<p style="text-indent: 28px;">商品数量：<span>{$rs[goods_count_num]}</span></p>
				<p id="p_delivery" style="text-indent: 56px;">运费：{MONUNIT}<span>0.00</span></p>
				<p id="p_promotion" style="text-indent: 28px;">订单促销：{MONUNIT}-<span>0.00</span></p>
				<p id="p_coupons" style="text-indent: 14px;">优惠券抵扣：{MONUNIT}<span>0.00</span></p>
				<p id="p_invoicerate" style="text-indent: 28px;display: none;">发票税率：{MONUNIT}<span>0.00</span></p>
				<p id="p_give_point" style="text-indent: 28px;">获得积分：<span>0</span></p>
				<!--<p class="total-span3">实付订单金额：{MONUNIT}<span id="real_amount" class="money-pay">0</span> </p>-->
				<p class="total-span3">实付订单金额：{MONUNIT}<span id="real_amount" class="money-pay">0.00</span> </p>
				<a href="javascript:;" onclick="hd_order.submit();"><div class="agree-order-fr-btn">提交订单</div></a>
			</div>
		</div>
	</div>
	<div class="clear"></div>
	<div class="clear"></div>
</div>
<!--商品结束-->
<!--footer-->
<!--{subtemplate common/footer}-->
<!--添加新地址-->
<div class="add-new-address-content" id="add-new-address" >
	<div class="add-new-name">
		<span>收货人：</span>
		<input type="text" class="add-new-name-span" name="address[address_name]">
	</div>
	<div class="add-new-name">
		<span>手机号：</span>
		<input type="text" class="add-new-name-span" name="address[mobile]">
	</div>
	<div class="add-new-area">
		<span>收货地区：</span>
		<select id="add-new-area-select" style="margin-left:12px"></select>
	</div>
	<div class="add-new-specific">
		<span>详细地址：</span>
		<input type="text" class="add-new-name-span-2" name="address[address]">
	</div>
	<div class="add-new-email">
		<span>邮政编码：</span>
		<input type="text" class="add-new-name-span-3" name="address[zipcode]">
	</div>
</div>
<style type="text/css">
.error {
    border: 1px solid #e9bb89;
    color: rgb(255, 0, 0);
    display: none;
    line-height: 30px;
    margin: 13px 0 -2px 0;
    padding: 0 10px;
    background-color: #fffbea;
}
</style>
<script type="text/javascript" src="{THEME_PATH}js/order.js"></script>
<script type="text/javascript" src="{JS_PATH}linkage.min.js"></script>
<script type="text/javascript">
{if !$address_id}
hd_order.setAddress($("#address-box div.add-address-1").eq(0));
{/if}
$("#pay_type_box input[name=pay_type]").eq(0).prop("checked", "checked");
$("#delivery_box input[name=delivery_id]").eq(0).prop("checked", "checked");
$(".add-address-1").live('click', function(){
	hd_order.setAddress(this);
})
$("input[name=pay_type],input[name=delivery_id]").live('click', function(){
	// 当选择配送方式时清空支付方式的值
	if ($(this).attr('name') == 'delivery_id') {
		$("#pay_type_box input[name=pay_type]:checked").attr('checked',false);
	}
	hd_order.init();
})
/* 发票切换 */
function switch_tab() {
	if($("input[name=invoicerate]").attr('checked') == 'checked') {
		$(".agree-order-fl-2").show();
	} else {
		$(".agree-order-fl-2").hide();
	}
}
hd_order.init();
var options = {
	select:  '#add-new-area-select',
	data:{json_encode($region)},
	selClass:'add-new-area-select',
	selStyle:'margin-left:8px;width:120px',
	head:'请选择城市',
	dataReader: {id: 'area_id', name: 'area_name', cell:'_child'}
}
var address = {
	'province' : 0,
	'city' : 0,
	'district' : 0
}
var oAddress = $('#add-new-address');
var _posturl = "{U('User/Address/update')}";
var _postdata = address;
var linkage = new LinkageSel(options);
linkage.onChange(function() {
	var arr = this.getSelectedArr();
	address.province = arr[0] || 0;
	address.city = arr[1] || 0;
	address.district = arr[2] || 0;
})
/* 添加收货地址 */
$(".add-address").click(function() {
	address.province = 0;
	address.city     = 0;
	address.district = 0;
	_postdata.id = 0;
	oAddress.find("input[name='address[address_name]']").attr('value', '');
	oAddress.find("input[name='address[mobile]']").attr('value', '');
	oAddress.find("input[name='address[address]']").attr('value', '');
	oAddress.find("input[name='address[zipcode]']").attr('value', '');
	linkage.changeValues([0], options);
	_dialog('add');
});
/* 编辑收货地址 */
$(".add-address-make").live('click', function() {
	address.province = $(this).parents('div.add-address-1').attr('data-province');
	address.city     = $(this).parents('div.add-address-1').attr('data-city');
	address.district = $(this).parents('div.add-address-1').attr('data-district');
	_postdata.id = $(this).parents('div.add-address-1').attr('data-addressid');
	oAddress.find("input[name='address[address_name]']").attr('value', $(this).parents('div.add-address-1').attr('data-address_name'));
	oAddress.find("input[name='address[mobile]']").attr('value', $(this).parents('div.add-address-1').attr('data-mobile'));
	oAddress.find("input[name='address[address]']").attr('value', $(this).parents('div.add-address-1').attr('data-address'));
	oAddress.find("input[name='address[zipcode]']").attr('value', $(this).parents('div.add-address-1').attr('data-zipcode'));
	linkage.changeValues(json2str());
	_dialog('update');
});
function json2str() {
	var a = Array();
	$.each(address, function(i, n) {
		a.push(n);
	});
	return a;
}
function _dialog(method) {
	method = method || 'add';
    art.dialog({
        id: method + '-address',
        background: '#6d6d6d',
        opacity: 0.5,
        fixed:true,
        lock:true,
        title: '添加新地址',
        content: document.getElementById('add-new-address'),
        ok:function() {
        	var address_name = oAddress.find('input[name="address[address_name]"]');
        	var mobile = oAddress.find('input[name="address[mobile]"]');
        	var address = oAddress.find('input[name="address[address]"]');
        	var zipcode = oAddress.find('input[name="address[zipcode]"]');
        	if(address_name.val().length == 0) {
        		address_name.focus();
        		alert('收货人姓名不能为空');
        		return false;
        	}
        	if(mobile.val().length == 0){
        		mobile.focus();
        		alert('手机号不能为空');
        		return false;
        	}
        	if(address.val().length == 0){
        		address.focus();
        		alert('收货详细地址不能为空');
        		return false;
        	}
        	if(zipcode.val().length == 0){
        		zipcode.focus();
        		alert('地区邮编不能为空');
        		return false;
        	}
        	_postdata.address_name = address_name.val();
        	_postdata.mobile = mobile.val();
        	_postdata.address = address.val();
        	_postdata.zipcode = zipcode.val();
        	_postdata.ajax = 1;
        	if(_postdata.province < 1 || _postdata.city < 1 || _postdata.district < 1) {
        		alert('请选择完整的收货地区');
        		return false;
        	}
        	$.ajax({
        		type: 'GET',
        		url: _posturl,
        		data:_postdata,
        		dataType:'JSON',
        		async:true,
        		success:function(ret) {
        			if(ret.status == 1) {
        				var _html = '';
        				if(method == 'update') {
        					var domAddress = $("div[data-addressid="+ret.id+"]");
        					domAddress.attr('data-province', ret.province);
        					domAddress.attr('data-city', ret.city);
        					domAddress.attr('data-district', ret.district);
        					domAddress.attr('data-address_name', ret.address_name);
        					domAddress.attr('data-address', ret.address);
        					domAddress.attr('data-zipcode', ret.zipcode);
        					domAddress.attr('data-mobile', ret.mobile);
        					domAddress.find('.add-address-name1').text(ret.address_name);
        					domAddress.find('.add-address-name2').text(ret.mobile);
        					domAddress.find('.add-address-address').html('<b>寄送至</b>' + ret.province_name + ' ' + ret.city_name + '' + ret.district_name + ' ' + ret.address);
        					hd_order.setAddress();
        				} else {
        					_html += '<div class="add-address-1" data-addressid="'
        					+ ret.id +'" data-province="'
        					+ ret.province +'" data-city="'
        					+ ret.cify +'" data-district="'
        					+ ret.district +'" data-address_name="'
        					+ ret.address_name +'" data-address="'
        					+ ret.address +'" data-zipcode="'
        					+ ret.zipcode +'" data-mobile="'
        					+ ret.mobile +'"><div class="border-img-top"><img src="{THEME_PATH}images/homeimages/border-top_03.png" alt=""></div><div class="border-img-top-2" style="display: none;"><img src="{THEME_PATH}images/homeimages/border-img-1.png" alt=""></div><p class="add-address-name"><span class="add-address-name1">'
        					+ ret.address_name +'</span><span class="add-address-name2">'
        					+ ret.mobile +'</span><span class="add-address-name3" style="display:none;">默认</span></p><p class="add-address-address"><b>寄送至</b>  '
        					+ ret.province_name + ' ' + ret.city_name + ' ' + ret.district_name + ' ' + ret.address + '</p><p class="add-address-make" style="display: none;">修改</p></div>';
        					$("#address-box .add-address").before(_html);
        				}
        				hd_order.setAddress($("div.add-address-1[data-addressid="+ret.id+"]"));
        			} else {
        				alert(ret.info);
        				return false;
        			}
        		}
        	});
        	return true;
        },
        cancel:true
    });
}
</script>
</body>
</html>